<template>
    <!-- 产品详情-box -->
    <view class="good-info-box">
        <view class="g-i-a">
            <view>
                <text class="a-title">品名：</text>
                <text>{{ goodInfo.title }}</text>
            </view>
            <view>
                <text class="a-title">货号：</text>
                <text>{{ goodInfo.item_no }}</text>
            </view>
            <view>
                <text class="a-title">条码：</text>
                <text>{{
                    goodInfo.barcode ? goodInfo.barcode : "暂无条码"
                }}</text>
            </view>
        </view>
        <view class="g-i-a">
            <view>
                <text class="a-title">规格：</text>
                <text>{{
                    goodInfo.spec_ls_name ? goodInfo.spec_ls_name : "暂无规格"
                }}</text>
            </view>
            <view>
                <text class="a-title">单位：</text>
                <text v-for="(item, index) in goodInfo.unitList" :key="index">
                    {{ index == 0 ? "" : "," }} {{ item.unitname }}</text
                >
            </view>
        </view>
        <view class="g-i-a">
            <view>
                <text class="a-title">售价：</text>
                <text class="price"
                    ><text class="b-z-price"></text>
                    {{ goodInfo.price_bw }}</text
                >
            </view>
            <view
                v-if="
                    tplinfo.pricec == 1 && filterPrice('1', goodInfo.priceinfo)
                "
            >
                <text class="a-title">划线价：</text>
                <text class="price scribing-price"
                    ><text class="b-z-price"></text>
                    {{ filterPrice("1", goodInfo.priceinfo) }}</text
                >
            </view>
            <view
                v-if="
                    tplinfo.money_q == 1 && filterPrice('2', goodInfo.priceinfo)
                "
            >
                <text class="a-title">消费券：</text>
                <text class="price"
                    ><text class="b-z-price"></text>
                    {{ filterPrice("2", goodInfo.priceinfo) }}</text
                >
            </view>
            <view v-if="isShowCost">
                <text class="a-title">成本：</text>
                <text class="price"
                    ><text class="b-z-price"></text>
                    {{ goodInfo.cost_bw }}</text
                >
            </view>
        </view>
        <view class="g-i-a">
            <view>
                <text class="a-title">品牌：</text>
                <text>{{
                    goodInfo.brands_title ? goodInfo.brands_title : "暂无品牌"
                }}</text>
            </view>
            <view>
                <text class="a-title">类别：</text>
                <text>{{
                    goodInfo.categoryname ? goodInfo.categoryname : "暂无类别"
                }}</text>
            </view>
            <view>
                <text class="a-title">标签：</text>
                <text>{{
                    goodInfo.tags_title ? goodInfo.tags_title : "暂无标签"
                }}</text>
            </view>
            <view>
                <text class="a-title">分享：</text>
                <text>{{
                    goodInfo.txt_share ? goodInfo.txt_share : "暂无分享内容"
                }}</text>
            </view>
        </view>
        <view class="g-i-a">
            <view>
                <text class="txt-h" @click="getsaleDataFun('1')">
                    <text>历史销售</text>
                    <text class="qty-m icon-font icon-style">&#xe600;</text>
                </text>
            </view>
            <view>
                <text class="txt-h" @click="getsaleDataFun('2')">
                    <text>月度销售</text>
                    <text class="qty-m icon-font icon-style">&#xe600;</text>
                </text>
            </view>
            <view>
                <text class="txt-h" @click="getsaleDataFun('3')">
                    <text>客户销售</text>
                    <text class="qty-m icon-font icon-style">&#xe600;</text>
                </text>
            </view>
        </view>
        <view class="g-i-a">
            <view>
                <text class="a-title">库存数量：</text>
                <text class="qty-m icon-font icon-style" @click="onClickQty"
                    >{{ qty }}&#xe600;</text
                >
            </view>
        </view>
    </view>
</template>

<script>
import accessCtrl from "../../js/limit/AccessCtrl.js";
import goodsTlpCtrl from "../../js/gd/GoodsTlpCtrl.js";

export default {
    props: ["goodInfo", "qty", "tplinfo"],
    data() {
        return {
            isShowCost: false,
            ishasCoupons: false,
            ishasPricec: false,
        };
    },
    async created() {
        this.isShowCost = await accessCtrl.getGdsCostSeeLimit();
        this.initData();
    },
    methods: {
        getsaleDataFun(type){
            this.$emit('getsaleDataFun',type)
        },
        filterPrice(type, data) {
            let arr = [];
            let min = "";
            let max = "";
            let pricedata = "";
            let result = "";
            if (type == 1) {
                if (data && data.length > 0) {
                    data.map((v) => {
                        if (v.pricec > 0) {
                            arr.push(v.pricec);
                        }
                    });
                }
            } else {
                if (data && data.length > 0) {
                    data.map((v) => {
                        if (v.priceinfo && v.priceinfo.length > 0) {
                            v.priceinfo.map((vs) => {
                                if (vs.money_q > 0) {
                                    arr.push(vs.money_q);
                                }
                            });
                        }
                    });
                }
            }
            arr = arr.sort((a, b) => {
                return a - b;
            });
            min = arr[0];
            max = arr[arr.length - 1];
            result = arr.every((item) => item === min);
            if (result) {
                //全部都一样
                pricedata = min;
            } else if (arr.length == 0) {
                // 全部为0
                pricedata = "";
            } else {
                pricedata = `${min}-${max}`;
            }
            return pricedata;
        },
        initData() {
            this.ishasCoupons = goodsTlpCtrl.hasCoupons();
            this.ishasPricec = goodsTlpCtrl.hasPricec();
        },
        onClickQty() {
            this.$emit("gdStoreWin");
        },
    },
};
</script>

<style lang="scss" scoped>
// 产品详情-box
.good-info-box {
    padding-left: 20px;
    .g-i-a {
        border-bottom: 1px solid #eee;
        padding: 10px 0;
        color: #333;
        font-size: 14px;
        .a-title {
            color: #9fa0a8;
        }
        .price {
            color: #f04848;
            &.scribing-price {
                text-decoration: line-through;
                color: #9fa0a8;
            }
            .b-z-price {
                font-size: 12px;
            }
        }
        .qty-m {
            color: #333;
            cursor: pointer;
        }
        // .qty-m:hover {
        //     color: #3388ff;
        // }
        .txt-h {
            cursor: pointer;
            &:hover {
                color: #3388ff;
                .qty-m {
                    color: #3388ff;
                }
            }
        }
    }
}
</style>
